import 'package:flutter/material.dart';

class FirstDemoPage extends StatefulWidget {
  final String title;

  const FirstDemoPage({super.key, required this.title});

  @override
  State<StatefulWidget> createState() {
    return _FirstDemoPageState();
  }
}

class _FirstDemoPageState extends State<FirstDemoPage> {
  final List _imageNames = [
    {'image': 'images/avatar.png', 'text': '岛上码农'},
    {'image': 'images/qrcode.png', 'text': '扫码关注'},
  ];
  late int _index = 0;

  void _onSwitch() {
    setState(() {
      _index = (++_index) % _imageNames.length;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: SizedBox(
          width: 300,
          height: 300,
          child: Column(
            children: [
              Container(
                width: 128,
                height: 128,
                margin: const EdgeInsets.only(top: 10, bottom: 10),
                child: Image.asset(
                  _imageNames[_index]['image'],
                  fit: BoxFit.cover,
                ),
              ),
              Text(_imageNames[_index]['text'])
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _onSwitch,
        tooltip: '切换',
        child: const Icon(Icons.swap_horizontal_circle_outlined),
      ),
    );
  }
}